package javabase.xml.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

/**
 * @Auther: luzhanshi
 * @Date: 2021/2/21 - 02 - 21 - 22:42 
 * @Description: javabase.xml.jsoup
 * @version: 1.0
 */
public class JsoupDemo1 {
    public static void main(String[] args) throws IOException {
        //2.获取 Document对象,根据XML文档进行获取
        //2.1获取student.xml文件的path
        String path = JsoupDemo1.class.getClassLoader().getResource("student.xml").getPath();
        //2.2解析xml文档，加载文档到内存，获取DOM树--->Document
        Document document = Jsoup.parse(new File(path), "utf-8");
        //3.获取元素对象
        Elements names = document.getElementsByTag("name");
        System.out.println(names.size());//2
        //3.1获取第一个name的Element对象
        Element element = names.get(0);
        //3.2获取数据
        String name = element.text();
        System.out.println(name);//tom
    }

}
